home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Atari Compendium
/
The Atari Compendium (Toad Computers) (1994).iso
/
files
/
umich
/
utils
/
sort.arc
/
fastcmp.asm
next >
Wrap
Assembly Source File
|
1989-03-30
|
11KB
|
602 lines
******************************************************************************
* *
* fastcmp.asm version 1.0 of 22 Januari 1989 (C) L.J.M. de Wit 1989 *
* *
* This software may be used and distributed freely if not used commercially *
* and the originator (me) is mentioned in the source (just leave this 9 line *
* header intact). *
* *
******************************************************************************
*
* fastcmp.asm: fast sort functions
*
* The code here presented is offered as a replacement for some of the C
* functions present in sortcomp.c. Since comparisions are done a lot while
* sorting, some performance tweaking didn't seem misplaced.
*
* As for documentation, a reference is made to the corresponding C functions
* in sortcomp.c. Most of the code here does simple work, like swapping
* arguments (for the 'r' options), and/or skipping white space (for the 'b'
* options; marked by 'skips' labels).
*
section s.ccode
tab equ 9
xref c_df
xref c_d
xref c_if
xref c_i
xref c_af
xref c_dfu
xref c_du
xref c_ifu
xref c_iu
xref c_afu
xdef c_dbfr
c_dbfr
* Dict/Blank/Fold/Reverse *
move.l 4(sp),a0
move.l 8(sp),4(sp)
move.l a0,8(sp)
move.l 12(sp),a0
move.l 16(sp),12(sp)
move.l a0,16(sp)
* FALLTHROUGH
xdef c_dbf
c_dbf
* Dict/Blank/Fold *
movea.l 4(sp),a0
movea.l 8(sp),a1
skips0a
move.b (a0)+,d0
cmp.b #' ',d0
beq.s skips0a
cmp.b #tab,d0
beq.s skips0a
subq.l #1,a0
skips1a
move.b (a1)+,d1
cmp.b #' ',d1
beq.s skips1a
cmp.b #tab,d1
beq.s skips1a
subq.l #1,a1
move.l a0,4(sp)
move.l a1,8(sp)
jmp c_df
xdef c_dbr
c_dbr
* Dict/Blank/Reverse *
move.l 4(sp),a0
move.l 8(sp),4(sp)
move.l a0,8(sp)
move.l 12(sp),a0
move.l 16(sp),12(sp)
move.l a0,16(sp)
* FALLTHROUGH
xdef c_db
c_db
* Dict/Blank *
movea.l 4(sp),a0
movea.l 8(sp),a1
skips0b
move.b (a0)+,d0
cmp.b #' ',d0
beq.s skips0b
cmp.b #tab,d0
beq.s skips0b
subq.l #1,a0
skips1b
move.b (a1)+,d1
cmp.b #' ',d1
beq.s skips1b
cmp.b #tab,d1
beq.s skips1b
subq.l #1,a1
move.l a0,4(sp)
move.l a1,8(sp)
jmp c_d
xdef c_dfr
c_dfr
* Dict/Fold/Reverse *
move.l 4(sp),a0
move.l 8(sp),4(sp)
move.l a0,8(sp)
move.l 12(sp),a0
move.l 16(sp),12(sp)
move.l a0,16(sp)
jmp c_df
xdef c_dr
c_dr
* Dict/Reverse *
move.l 4(sp),a0
move.l 8(sp),4(sp)
move.l a0,8(sp)
move.l 12(sp),a0
move.l 16(sp),12(sp)
move.l a0,16(sp)
jmp c_d
xdef c_ibfr
c_ibfr
* Norm/Blank/Fold/Reverse *
move.l 4(sp),a0
move.l 8(sp),4(sp)
move.l a0,8(sp)
move.l 12(sp),a0
move.l 16(sp),12(sp)
move.l a0,16(sp)
* FALLTHROUGH
xdef c_ibf
c_ibf
* Norm/Blank/Fold *
movea.l 4(sp),a0
movea.l 8(sp),a1
skips0c
move.b (a0)+,d0
cmp.b #' ',d0
beq.s skips0c
cmp.b #tab,d0
beq.s skips0c
subq.l #1,a0
skips1c
move.b (a1)+,d1
cmp.b #' ',d1
beq.s skips1c
cmp.b #tab,d1
beq.s skips1c
subq.l #1,a1
move.l a0,4(sp)
move.l a1,8(sp)
jmp c_if
xdef c_ibr
c_ibr
* Norm/Blank/Reverse *
move.l 4(sp),a0
move.l 8(sp),4(sp)
move.l a0,8(sp)
move.l 12(sp),a0
move.l 16(sp),12(sp)
move.l a0,16(sp)
* FALLTHROUGH
xdef c_ib
c_ib
* Norm/Blank *
movea.l 4(sp),a0
movea.l 8(sp),a1
skips0d
move.b (a0)+,d0
cmp.b #' ',d0
beq.s skips0d
cmp.b #tab,d0
beq.s skips0d
subq.l #1,a0
skips1d
move.b (a1)+,d1
cmp.b #' ',d1
beq.s skips1d
cmp.b #tab,d1
beq.s skips1d
subq.l #1,a1
move.l a0,4(sp)
move.l a1,8(sp)
jmp c_i
xdef c_ifr
c_ifr
* Norm/Fold/Reverse *
move.l 4(sp),a0
move.l 8(sp),4(sp)
move.l a0,8(sp)
move.l 12(sp),a0
move.l 16(sp),12(sp)
move.l a0,16(sp)
jmp c_if
xdef c_ir
c_ir
* Norm/Reverse *
move.l 4(sp),a0
move.l 8(sp),4(sp)
move.l a0,8(sp)
move.l 12(sp),a0
move.l 16(sp),12(sp)
move.l a0,16(sp)
jmp c_i
xdef c_abfr
c_abfr
* Blank/Fold/Reverse *
move.l 4(sp),a0
move.l 8(sp),4(sp)
move.l a0,8(sp)
move.l 12(sp),a0
move.l 16(sp),12(sp)
move.l a0,16(sp)
* FALLTHROUGH
xdef c_abf
c_abf
* Blank/Fold *
movea.l 4(sp),a0
movea.l 8(sp),a1
skips0e
move.b (a0)+,d0
cmp.b #' ',d0
beq.s skips0e
cmp.b #tab,d0
beq.s skips0e
subq.l #1,a0
skips1e
move.b (a1)+,d1
cmp.b #' ',d1
beq.s skips1e
cmp.b #tab,d1
beq.s skips1e
subq.l #1,a1
move.l a0,4(sp)
move.l a1,8(sp)
jmp c_af
xdef c_abr
c_abr
* Blank/Reverse *
move.l 4(sp),a0
move.l 8(sp),4(sp)
move.l a0,8(sp)
move.l 12(sp),a0
move.l 16(sp),12(sp)
move.l a0,16(sp)
* FALLTHROUGH
xdef c_ab
c_ab
* Blank *
movea.l 4(sp),a0
movea.l 8(sp),a1
skips0f
move.b (a0)+,d0
cmp.b #' ',d0
beq.s skips0f
cmp.b #tab,d0
beq.s skips0f
subq.l #1,a0
skips1f
move.b (a1)+,d1
cmp.b #' ',d1
beq.s skips1f
cmp.b #tab,d1
beq.s skips1f
subq.l #1,a1
move.l a0,4(sp)
move.l a1,8(sp)
jmp c_a
xdef c_afr
c_afr
* Fold/Reverse *
move.l 4(sp),a0
move.l 8(sp),4(sp)
move.l a0,8(sp)
move.l 12(sp),a0
move.l 16(sp),12(sp)
move.l a0,16(sp)
jmp c_af
xdef c_ar
c_ar
* Reverse *
move.l 4(sp),a0
move.l 8(sp),4(sp)
move.l a0,8(sp)
move.l 12(sp),a0
move.l 16(sp),12(sp)
move.l a0,16(sp)
jmp c_a
xdef c_a
c_a
move.l 4(sp),d0
move.l 12(sp),d1
sub.l d0,d1
move.l d0,a0
move.l 8(sp),d0
move.l 16(sp),d2
sub.l d0,d2
move.l d0,a1
move.w d2,d0
sub.w d1,d0
blt.s c_asmall
move.w d1,d2
c_asmall
dbra d2,c_aloop
c_aeqs
ext.l d0
rts
c_aloop
cmp.b (a0)+,(a1)+
dbne d2,c_aloop
beq.s c_aeqs
bpl.s c_aplus
moveq.l #1,d0
rts
c_aplus
moveq.l #-1,d0
rts
* Unbounded comparisions start here *
xdef c_dbfru
c_dbfru
* Dict/Blank/Fold/Reverse *
move.l 4(sp),a1
move.l 8(sp),a0
bra.s skips0g
xdef c_dbfu
c_dbfu
* Dict/Blank/Fold *
movea.l 4(sp),a0
movea.l 8(sp),a1
skips0g
move.b (a0)+,d0
cmp.b #' ',d0
beq.s skips0g
cmp.b #tab,d0
beq.s skips0g
subq.l #1,a0
skips1g
move.b (a1)+,d1
cmp.b #' ',d1
beq.s skips1g
cmp.b #tab,d1
beq.s skips1g
subq.l #1,a1
move.l a0,4(sp)
move.l a1,8(sp)
jmp c_dfu
xdef c_dbru
c_dbru
* Dict/Blank/Reverse *
move.l 4(sp),a1
move.l 8(sp),a0
bra.s skips0h
xdef c_dbu
c_dbu
* Dict/Blank *
movea.l 4(sp),a0
movea.l 8(sp),a1
skips0h
move.b (a0)+,d0
cmp.b #' ',d0
beq.s skips0h
cmp.b #tab,d0
beq.s skips0h
subq.l #1,a0
skips1h
move.b (a1)+,d1
cmp.b #' ',d1
beq.s skips1h
cmp.b #tab,d1
beq.s skips1h
subq.l #1,a1
move.l a0,4(sp)
move.l a1,8(sp)
jmp c_du
xdef c_dfru
c_dfru
* Dict/Fold/Reverse *
move.l 4(sp),a0
move.l 8(sp),4(sp)
move.l a0,8(sp)
jmp c_dfu
xdef c_dru
c_dru
* Dict/Reverse *
move.l 4(sp),a0
move.l 8(sp),4(sp)
move.l a0,8(sp)
jmp c_du
xdef c_ibfru
c_ibfru
* Norm/Blank/Fold/Reverse *
move.l 4(sp),a1
move.l 8(sp),a0
bra.s skips0i
* FALLTHROUGH
xdef c_ibfu
c_ibfu
* Norm/Blank/Fold *
movea.l 4(